package com.clgk.wechatmall.common;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.clgk.wechatmall.common.constants.Constants;
import com.clgk.wechatmall.manager.entity.ManagerVo;

public class BaseAction {

	protected HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest();
		return request;
	}

	protected HttpSession getSession() {
		return this.getRequest().getSession();
	}

	/**
	 * 获取前台用户登录信息
	 * */
	protected ManagerVo getBackInfo() {
		ManagerVo UserInfoVo = (ManagerVo) this.getSession().getAttribute(Constants.SESSION_USER_KEY);
		return UserInfoVo;
	}
	
	/**
	 * 获得传递的参数
	 */
	@SuppressWarnings("rawtypes")
	protected String getParameters() {
		Enumeration param = this.getRequest().getParameterNames();
		StringBuffer buffer = new StringBuffer();
		String msg = "";
		while (param.hasMoreElements()) {
			String paramName = (String) param.nextElement();
			buffer.append("&" + paramName + ":"
					+ this.getRequest().getParameter(paramName));
		}
		if (StringUtils.isNotEmpty(buffer.toString())) {
			msg = buffer.toString().substring(1);
		}
		return msg;
	}
}
